package com.xd.user.controller;


import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.xd.common.model.R;
import com.xd.common.base.BaseController;
import com.xd.user.api.entity.Role;
import com.xd.user.api.feign.RoleFeign;
import com.xd.user.service.RoleService;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;
import io.swagger.annotations.Api;
import lombok.extern.slf4j.Slf4j;
import org.springframework.transaction.annotation.Transactional;

/**
 * 用户角色(Role)表控制层
 *
 * @author hbx
 * @since 2019-12-30 17:17:24
 */
@Slf4j
@RestController
@RequestMapping("role")
@Api
@Transactional(rollbackFor = Exception.class)
public class RoleController extends BaseController<RoleService,Role,String> implements RoleFeign {



    /**
     * @author huboxin
     * @description: TODO 设置为默认角色
     * @param id id
     * @date 15:43 2020/7/11
     * @return com.baomidou.mybatisplus.extension.api.R<java.lang.Boolean>
     **/
    @ApiOperation(value = "设置为默认角色",notes = "设置为默认角色")
    @ApiImplicitParams({
    	@ApiImplicitParam(name="id",value = "id"),
    })
    @GetMapping("setDefault/{id}")
    public R<Boolean> setDefault(@PathVariable  String id){
        boolean update = this.service.update(Wrappers.<Role>lambdaUpdate().set(Role::getDefaultRole, false));
        if(ObjectUtil.isEmpty(update)){
            return failed("设置失败");
        }
        boolean update1 = this.service.update(Wrappers.<Role>lambdaUpdate().eq(Role::getId, id)
                .set(Role::getDefaultRole, true));
        return update1?success(true):failed("设置失败");
    }
}
